//
//  HelpDetailVC.m
//  智慧小区
//
//  Created by 高永杨 on 2017/3/17.
//  Copyright © 2017年 zhongchuang. All rights reserved.
//

#import "HelpDetailVC.h"
#import "HelpDetailCell.h"
#import <AFNetworking.h>
#import <MJRefresh.h>
@interface HelpDetailVC ()<UITableViewDelegate,UITableViewDataSource,HelpDetailCellDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *dataArr;
@end

@implementation HelpDetailVC
static NSString *cellID = @"cellID";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"接受帮助";
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([HelpDetailCell class]) bundle:nil] forCellReuseIdentifier:cellID];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(reloadData)];
    //    self.tableVie.mj_header.automaticallyChangeAlpha = YES;
    [self.tableView.mj_header beginRefreshing];
//    [self reloadData];
    [self setNav:self];
    // Do any additional setup after loading the view from its nib.
}
-(void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)reloadData
{
    [SVProgressHUD showWithStatus:@"正在加载中...."];
    NSMutableDictionary *muteDict = [NSMutableDictionary dictionary];
    [muteDict setObject:@"23" forKey:@"opt"];
    [muteDict setObject:self.tempID forKey:@"serviceId"];
    [muteDict setObject:@"e4022b7ca0e3f31048c3c4ac30ae3967" forKey:@"token"];
[[AFHTTPSessionManager manager]GET:GolobaUrl parameters:muteDict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    [SVProgressHUD showSuccessWithStatus:@"刷新成功"];
    [self.tableView.mj_header endRefreshing];
    self.dataArr = responseObject[@"results"];
    [self.tableView reloadData];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    [SVProgressHUD showErrorWithStatus:@"刷新失败"];
    [self.tableView.mj_header endRefreshing];
}];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HelpDetailCell *detailCell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    detailCell.delegate = self;
    [detailCell sendDataArr:self.dataArr[indexPath.row]];
    return detailCell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}
-(void)receiveAndrejest:(UIButton *)sender{
    HelpDetailCell *detailCell = (HelpDetailCell *)[sender superview].superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:detailCell];
    NSDictionary *diction = self.dataArr[indexPath.row];
    NSMutableDictionary *muteDict = [NSMutableDictionary dictionary];
    muteDict[@"id"] = diction[@"id"];
    if ([sender.currentTitle isEqualToString:@"接受"]) {
        muteDict[@"status"] = @"2";
    }else{
        muteDict[@"status"] = @"3";
    }
    muteDict[@"opt"] = @"25";
    muteDict[@"token"] = @"a9dd88d9aedccfa75fd63fd62bcc4306";
    muteDict[@"category"] = @"1";
    muteDict[@"serviceId"] = diction[@"serviceId"];
    muteDict[@"serviceUserId"] = diction[@"recipientUserId"];
    [self senParms:muteDict];
}

-(void)senParms:(NSDictionary *)parmars
{
    
    [SVProgressHUD showWithStatus:@"正在提交申请中"];
[[AFHTTPSessionManager manager]POST:GolobaUrl parameters:parmars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    [SVProgressHUD showSuccessWithStatus:@"提交申请成功"];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    [SVProgressHUD showErrorWithStatus:@"提交申请失败"];

}];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
